package co.laomag.coffee.controller.article;

import cn.hutool.core.date.DateUtil;
import co.laomag.coffee.api.article.ArticleApi;
import co.laomag.coffee.model.entity.ChDiscovery;
import co.laomag.coffee.model.vo.Message;
import co.laomag.coffee.model.vo.Pagination;
import co.laomag.coffee.service.article.ArticleService;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 马泽朋
 * @version 1.0
 * @date 2020/4/18 下午 7:55
 */
@RestController
public class ArticleController implements ArticleApi {

    @Resource
    private ArticleService articleService;

    @Override
    public Message postDiscoveryArticle(ChDiscovery chDiscovery) {
        chDiscovery.setCreatetime(DateUtil.date());
        chDiscovery.setUpdatetime(DateUtil.date());
        Message message = articleService.postDiscoveryArticle(chDiscovery);
        return message;
    }

    @Override
    public Message getChDiscoveryList(Pagination pagination) {
        Message chDiscoveryList = articleService.getChDiscoveryList(pagination);
        return chDiscoveryList;
    }

    @Override
    public Message updateFoundArticles(ChDiscovery chDiscovery) {
        chDiscovery.setUpdatetime(DateUtil.date());
        Message message = articleService.updateByPrimaryKeySelective(chDiscovery);
        return message;
    }

    @Override
    public Message deleteFoundArticles(String discoveryId) {
        Message message = articleService.deleteFoundArticles(discoveryId);
        return message;
    }
}
